home *** CD-ROM | disk | FTP | other *** search
- /**************
- Debug Strip GH, a simple demonstration of how to write a
- control strip module. 8/18/94
-
- This module simply drops into MacsBug when clicked.
-
- Read the Software section of the Developer Notes on the Powerbook 500 series.
-
- I am unable to include the file "controlstrip.h", but it should be available
- in a variety of places.it is in the current Universal Header distribution (ETO 15)
- and should be available from Think or MetroWerks. (It isn't in MetroWerks CW4).
- You might check ftp.apple.com to see if there is an up-to-date Universal Header
- distribution there.
-
- There is an unofficial version that comes with the Control Strip Patcher
- *****************/
-
- #include "debug.h"
- #include <Icons.h>
- #include "controlstrip.h"
- pascal long main (long message, long params, Rect *statusRect, GrafPtr statusPort)
- {
- long result = 0L;
-
- switch (message)
- {
- case sdevInitModule: // check environs, allocate globals
- result = DoCSInit();
- break;
- case sdevCloseModule: // release my memory
- DoCSClose((MyGlobalHandle) params);
- break;
- case sdevFeatures: // let the strip track the mouse down
- result = (1L << sdevWantMouseClicks);
- break;
- case sdevGetDisplayWidth:
- result = 16L; // size of a small icon width
- break;
- case sdevPeriodicTickle:
- break;
- case sdevDrawStatus: // draw my icon
- DoCSDraw((MyGlobalHandle) params, statusRect, statusPort);
- break;
- case sdevMouseClick: // the mouse was clicked & released in my button
- DoCDClick((MyGlobalHandle) params);
- break;
- case sdevSaveSettings:
- break;
- case sdevShowBalloonHelp:
- break;
-
- }
- return (result);
- }
- void DoCDClick(MyGlobalHandle myGlobals)
- {
- Debugger();
- }
-
- long DoCSInit(void)
- {
- MyGlobalHandle myH;
- OSErr iErr;
- Handle iconSuite = 0L;
- if (HasDebugger()) // is a debugger installed?
- {
- myH = (MyGlobalHandle) NewHandleClear(sizeof(MyGlobals));
- if (myH) // was I able to allocate my memory?
- {
- iErr = SBGetDetachIconSuite(&iconSuite, 669, 0x0000FF00L);
- (*myH)->iconSuite = iconSuite;
- return ((long) myH);
- }
- }
- return (-1L); // something went wrong, don't install
- }
- void DoCSClose(MyGlobalHandle myGlobals)
- {
- if (myGlobals)
- {
- if ((*myGlobals)->iconSuite)
- {
- DisposeIconSuite ((*myGlobals)->iconSuite, true);
- }
- DisposeHandle((Handle) myGlobals);
- }
- }
- void DoCSDraw(MyGlobalHandle myGlobals, Rect *statusRect, GrafPtr statusPort)
- {
- OSErr iErr;
- Rect theRect;
- short alignment = 0x01 + 0x04; // center up & down , and left & right
- long transform = 0; // no transform
-
- if ((*myGlobals)->iconSuite)
- {
- theRect.top = statusRect->top;
- theRect.left = statusRect->left;
- theRect.bottom = statusRect->bottom;
- theRect.right = statusRect->right;
- iErr = PlotIconSuite(&theRect,alignment,transform,(*myGlobals)->iconSuite);
- }
- }
- Boolean HasDebugger(void)
- {
- OSErr err;
- long *jmpAddress;
-
- jmpAddress = (long *) 0x120L; // address of entry routine for a debugger
-
- if (*jmpAddress)
- return (true);
- else
- return (false);
- }